home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevbjcl.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  5.9 KB  |  253 lines

  1. /* Copyright (C) 1998 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevbjcl.c,v 1.2 2000/09/19 19:00:11 lpd Exp $*/
  20. /* Canon BJC command generation library */
  21. #include "std.h"
  22. #include "gdevbjcl.h"
  23.  
  24. /****** PRELIMINARY, SUBJECT TO CHANGE WITHOUT NOTICE. ******/
  25.  
  26. /* ---------------- Utilities ---------------- */
  27.  
  28. private void
  29. bjc_put_bytes(stream *s, const byte *data, uint count)
  30. {
  31.     uint ignore;
  32.  
  33.     sputs(s, data, count, &ignore);
  34. }
  35.  
  36. private void
  37. bjc_put_hi_lo(stream *s, int value)
  38. {
  39.     spputc(s, value >> 8);
  40.     spputc(s, value & 0xff);
  41. }
  42.  
  43. private void
  44. bjc_put_lo_hi(stream *s, int value)
  45. {
  46.     spputc(s, value & 0xff);
  47.     spputc(s, value >> 8);
  48. }
  49.  
  50. private void
  51. bjc_put_command(stream *s, int ch, int count)
  52. {
  53.     spputc(s, 033 /*ESC*/);
  54.     spputc(s, '(');
  55.     spputc(s, ch);
  56.     bjc_put_lo_hi(s, count);
  57. }
  58.  
  59. /* ---------------- Commands ---------------- */
  60.  
  61. /* Line feed (^J) */
  62. void
  63. bjc_put_LF(stream *s)
  64. {
  65.     spputc(s, 0x0a);
  66. }
  67.  
  68. /* Form feed (^L) */
  69. void
  70. bjc_put_FF(stream *s)
  71. {
  72.     spputc(s, 0x0c);
  73. }
  74.  
  75. /* Carriage return (^M) */
  76. void
  77. bjc_put_CR(stream *s)
  78. {
  79.     spputc(s, 0x0d);
  80. }
  81.  
  82. /* Return to initial condition (ESC @) */
  83. void
  84. bjc_put_initialize(stream *s)
  85. {
  86.     bjc_put_bytes(s, (const byte *)"\033@", 2);
  87. }
  88.  
  89. /* Set initial condition (ESC [ K <count> <init> <id> <parm1> <parm2>) */
  90. void
  91. bjc_put_set_initial(stream *s)
  92. {
  93.     bjc_put_bytes(s, (const byte *)"\033[K\002\000\000\017", 7);
  94. }
  95.  
  96. /* Set data compression (ESC [ b <count> <state>) */
  97. void
  98. bjc_put_set_compression(stream *s, bjc_raster_compression_t compression)
  99. {
  100.     bjc_put_command(s, 'b', 1);
  101.     spputc(s, compression);
  102. }
  103.  
  104. /* Select print method (ESC ( c <count> <parm1> <parm2> [<parm3>]) */
  105. void
  106. bjc_put_print_method_short(stream *s, bjc_print_color_short_t color)
  107. {
  108.     bjc_put_command(s, 'c', 1);
  109.     spputc(s, color);
  110. }
  111. void
  112. bjc_put_print_method(stream *s, bjc_print_color_t color,
  113.              bjc_print_media_t media, bjc_print_quality_t quality,
  114.              bjc_black_density_t density)
  115. {
  116.     bjc_put_command(s, 'c', 2 + (density != 0));
  117.     spputc(s, 0x10 | color);
  118.     spputc(s, (media << 4) | quality);
  119.     if (density)
  120.     spputc(s, density << 4);
  121. }
  122.  
  123. /* Set raster resolution (ESC ( d <count> <y_res> [<x_res>]) */
  124. void
  125. bjc_put_raster_resolution(stream *s, int x_resolution, int y_resolution)
  126. {
  127.     if (x_resolution == y_resolution) {
  128.     bjc_put_command(s, 'd', 2);
  129.     } else {
  130.     bjc_put_command(s, 'd', 4);
  131.     bjc_put_hi_lo(s, y_resolution);
  132.     }
  133.     bjc_put_hi_lo(s, x_resolution);
  134. }
  135.  
  136. /* Raster skip (ESC ( e <count> <skip>) */
  137. void
  138. bjc_put_raster_skip(stream *s, int skip)
  139. {
  140.     bjc_put_command(s, 'e', 2);
  141.     bjc_put_hi_lo(s, skip);
  142. }
  143.  
  144. /* Set page margins (ESC ( g <count> <length> <lm> <rm> <top>) */
  145. void
  146. bjc_put_page_margins(stream *s, int length, int lm, int rm, int top)
  147. {
  148.     byte parms[4];
  149.     int count;
  150.  
  151.     parms[0] = length, parms[1] = lm, parms[2] = rm, parms[3] = top;
  152.     count = 4;        /* could be 1..3 */
  153.     bjc_put_command(s, 'g', count);
  154.     bjc_put_bytes(s, parms, count);
  155. }
  156.  
  157. /* Set media supply method (ESC * l <count> <parm1> <parm2>) */
  158. void
  159. bjc_put_media_supply(stream *s, bjc_media_supply_t supply,
  160.              bjc_media_type_t type)
  161. {
  162.     bjc_put_command(s, 'l', 2);
  163.     spputc(s, 0x10 | supply);
  164.     spputc(s, type << 4);
  165. }
  166.  
  167. /* Identify ink cartridge (ESC ( m <count> <type>) */
  168. void
  169. bjc_put_identify_cartridge(stream *s,
  170.                bjc_identify_cartridge_command_t command)
  171. {
  172.     bjc_put_command(s, 'm', 1);
  173.     spputc(s, command);
  174. }
  175.  
  176. /* CMYK raster image (ESC ( A <count> <color>) */
  177. void
  178. bjc_put_cmyk_image(stream *s, bjc_cmyk_image_component_t component,
  179.            const byte *data, int count)
  180. {
  181.     bjc_put_command(s, 'A', count + 1);
  182.     spputc(s, component);
  183.     bjc_put_bytes(s, data, count);
  184. }
  185.  
  186. /* Move by raster lines (ESC ( n <count> <lines>) */
  187. void
  188. bjc_put_move_lines(stream *s, int lines)
  189. {
  190.     bjc_put_command(s, 'n', 2);
  191.     bjc_put_hi_lo(s, lines);
  192. }
  193.  
  194. /* Set unit for movement by raster lines (ESC ( o <count> <unit>) */
  195. void
  196. bjc_put_move_lines_unit(stream *s, int unit)
  197. {
  198.     bjc_put_command(s, 'o', 2);
  199.     bjc_put_hi_lo(s, unit);
  200. }
  201.  
  202. /* Set extended margins (ESC ( p <count> <length60ths> <lm60ths> */
  203. /*   <rm60ths> <top60ths>) */
  204. void
  205. bjc_put_extended_margins(stream *s, int length, int lm, int rm, int top)
  206. {
  207.     bjc_put_command(s, 'p', 8);
  208.     bjc_put_hi_lo(s, length);
  209.     bjc_put_hi_lo(s, lm);
  210.     bjc_put_hi_lo(s, rm);
  211.     bjc_put_hi_lo(s, top);
  212. }
  213.  
  214. /* Set image format (ESC ( t <count> <depth> <format> <ink>) */
  215. void
  216. bjc_put_image_format(stream *s, int depth, bjc_image_format_t format,
  217.                  bjc_ink_system_t ink)
  218.  
  219. {
  220.     bjc_put_command(s, 't', 3);
  221.     spputc(s, depth);
  222.     spputc(s, format);
  223.     spputc(s, ink);
  224. }
  225.  
  226. /* Page ID (ESC ( q <count> <id>) */
  227. void
  228. bjc_put_page_id(stream *s, int id)
  229. {
  230.     bjc_put_command(s, 'q', 1);
  231.     spputc(s, id);
  232. }
  233.  
  234. /* Continue raster image (ESC ( F <count> <data>) */
  235. void
  236. bjc_put_continue_image(stream *s, const byte *data, int count)
  237. {
  238.     bjc_put_command(s, 'F', count);
  239.     bjc_put_bytes(s, data, count);
  240. }
  241.  
  242. /* BJ indexed image (ESC ( f <count> R <dot_rows> <dot_cols> <layers> */
  243. /*   <index>) */
  244. void
  245. bjc_put_indexed_image(stream *s, int dot_rows, int dot_cols, int layers)
  246. {
  247.     bjc_put_command(s, 'f', 5);
  248.     spputc(s, 'R');            /* per spec */
  249.     spputc(s, dot_rows);
  250.     spputc(s, dot_cols);
  251.     spputc(s, layers);
  252. }
  253.